﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SortingSpace
{
    internal class exchangeSort : Sorting
    {
        int[] values;
        public exchangeSort(int[] values) { this.values = (int[])values.Clone(); }

        public void Sort() { this.values = Sort(new List<int>(values)).ToArray(); }

        public List<int> Sort(List<int> arr)
        {
            int size = arr.Count, ls = 0, rs = 0;
            if (size <= 1) return arr;

            List<int> leftPart = new(), rightPart = new();
            int pivot = arr[size / 2];
            for (int i = 0; i < size; i++)
            {
                if (arr[i] < pivot) leftPart.Add(arr[i]);
                else if (arr[i] > pivot) rightPart.Add(arr[i]);
            }

            leftPart = Sort(leftPart);
            rightPart = Sort(rightPart);
            int[] pv = [pivot];

            return leftPart.Concat(pv.Concat(rightPart).ToArray()).ToList();
        }

        public int[] getValues() { return values; }
        
        public string getName() { return "Quick sort"; }
    }
}
